// JavaScript Document
function check_register()
{
	$('#register_status').hide();
	if(checkUsername()==false)return false;
	$.post("register/checkavail.php",{username:$('#username').val()},function(data){
			if(data!="true")
			{
				$('#register_status').addClass('strykerError');
				$('#register_status').html('Userid already exists.').show().fadeOut(3000);
			}
			else
			{
				if(checkPassword()==false)return false;
				if(checkName()==false)return false;
				if(checkRoleDesgNo()==false)return false;
				if(checkSecurtity()==false)return false;		
			}
	});
}
function checkUsername()
{
		if($('#username').val()=="")
		{
			$('#register_status').addClass('strykerError');
			$('#register_status').html('Userid Required.').show();
			return false;
		}
		if($('#username').val().length>15)
		{
			$('#register_status').addClass('strykerWarn');
			$('#register_status').html('Userid should be less than 15 Charecters.').show().fadeOut(3000);
			return false;
		}
		if($('#username').val().length<3)
		{
			$('#register_status').addClass('strykerWarn');
			$('#register_status').html('Userid should be more than 3 Charecters.').show().fadeOut(3000);
			return false;
		}
		if($('#username').val().indexOf(' ')>=0)
		{
			$('#register_status').addClass('strykerWarn');
			$('#register_status').html('Spaces not allowed in User ID.').show().fadeOut(3000);
			return false;
		}
	if($('#username').val().indexOf('&')>=0 || $('#username').val().indexOf('!')>=0 || $('#username').val().indexOf('@')>=0 || $('#username').val().indexOf('#')>=0 || $('#username').val().indexOf('$')>=0 || $('#username').val().indexOf('%')>=0  || $('#username').val().indexOf('^')>=0 || $('#username').val().indexOf('~')>=0 || $('#username').val().indexOf('*')>=0  || $('#username').val().indexOf('?')>=0  || $('#username').val().indexOf('<')>=0 || $('#username').val().indexOf('>')>=0  || $('#username').val().indexOf(',')>=0 || $('#username').val().indexOf('/')>=0 || $('#username').val().indexOf('+')>=0 || $('#username').val().indexOf('=')>=0 || $('#username').val().indexOf(':')>=0 || $('#username').val().indexOf(';')>=0 || $('#username').val().indexOf('-')>=0 || $('#username').val().indexOf('(')>=0 || $('#username').val().indexOf(')')>=0 || $('#username').val().indexOf('"')>=0 || $('#username').val().indexOf("'")>=0)
		{
			$('#register_status').addClass('strykerWarn');
			$('#register_status').html('Special charecters like @,~,*,",..etc are not allowed.').show().fadeOut(3000);
			return false;
		}
		return true;
}
function checkPassword()
{
		if($('#password').val()==""||$('#repassword').val()=="")
		{
			$('#register_status').addClass('strykerError');
			$('#register_status').html('Password Required.').show();
			return false;
		}
		if($('#password').val().length<6)
		{
			$('#register_status').addClass('strykerWarn');
			$('#register_status').html('The password must be greater than 6 characters.').show().fadeOut(3000);
			return false;
		}
		if($('#password').val().length>40)
		{
			$('#register_status').addClass('strykerWarn');
			$('#register_status').html('The password must be less than 40 characters.').show().fadeOut(3000);
			return false;
		}
		if($('#password').val().indexOf(' ')>=0)
		{
			$('#register_status').addClass('strykerWarn');
			$('#register_status').html('Spaces not Allowed in password.').show().fadeOut(3000);
			return false;
		}
		if($('#repassword').val()!=$('#password').val())
		{
			$('#register_status').addClass('strykerError');
			$('#register_status').html('Your passwords are not match.').show().fadeOut(3000);
			return false;
		}
		return true;
}
function checkName()
{
	if($('#name').val()=="")
	{
		$('#register_status').addClass('strykerError');
		$('#register_status').html('Name Required.').show();
		return false;
	}
	return true;
}
function checkRoleDesgNo()
{
	if($('#role').val()==1)
	{
		if($('#regno').val()=="")
		{
			$('#register_status').addClass('strykerError');
			$('#register_status').html('Register number Required.').show();
			return false;
		}
		if($('#regno').val().length!=11)
		{
			$('#register_status').addClass('strykerError');
			$('#register_status').html('Register number not valid.').show().fadeOut(3000);
			return false;
		}
	}
	else
	{
		if($('#desg').val()=="")
		{
			$('#register_status').addClass('strykerError');
			$('#register_status').html('Designation Required.').show().fadeOut(3000);
			return false;
		}
	}
	return true;
}
function checkSecurtity()
{
	if($('#security').val()=="")
	{
		$('#register_status').addClass('strykerError');
		$('#register_status').html('Security code Required.').show();
		return false;
	}
	else
	{
		$.post("register/checkCaptcha.php",{security:$('#security').val()},function(data){
   		if(data=="ok")
   		{
			//update to DB;
			updateUser();
	     }
		else
		{
			$('#register_status').addClass('strykerError');
			$('#register_status').html('Security code not valid.').show();
		}	
		});
	}
}
function updateUser()
{
$.post("register/saveuser.php",{userid:$('#username').val(),password:$('#password').val(),role:$('#role').val(),name:$('#name').val(),regno:$('#regno').val(),commitee:$('#commitee').val(),year:$('#year').val(),house:$('#house').val(),email:$('#email').val(),desg:$('#desg').val()},function(use){
 if(use!="")
 {
	 	$.post("plugins/front_content.php",function(data){
					$('#notice').html('Your account added Sucessfully').show().fadeOut(6000);
						$('#entire').html(data);
										  });
 }
 else
 {
	 alert("Cannot update your account at this time");
 }
 });
}